/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kimstore.gui.stocksarrival;

import com.kimstore.bean.Batch;
import com.kimstore.bean.User;
import com.kimstore.factory.DaoFactory;
import com.kimstore.gui.main.Inventory;
import com.kimstore.main.controller.StocksArrivalTabController;

/**
 *
 * @author Administrator
 */
public class ViewBatchController {

    private StocksArrivalTabController parentController;
    private ViewBatchWindow window;
    private String batchNumber = null;
    private Batch batch = null;

    public ViewBatchController(StocksArrivalTabController parentController, String batchNumber) {
        this.parentController = parentController;
        this.batchNumber = batchNumber;
    }

    public void displayWindow() {
        window = new ViewBatchWindow(this);
        batch = DaoFactory.getInstance().getBatchDao().findByNumber(Long.parseLong(batchNumber));
        
        window.populateWindow(batch);
        window.showWindow();
    }
    
    public float getHiddenCost() {
        return batch.getPurchaseCost();
    }

    void fromWindow(float purchaseCost) {
        batch.setPurchaseCost(purchaseCost);
        
        DaoFactory.getInstance().getBatchDao().saveOrUpdate(batch);
        
        this.parentController.refreshTable();
    }
}
